package com.example.nick.bodyapplication.anim

import android.content.res.Resources
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.example.nick.bodyapplication.R

//使用示例
// 10.dp
inline val Double.dp2px: Int get() = run {
    return toFloat().dp2px
}
inline val Int.dp2px: Int get() = run {
    return toFloat().dp2px
}

inline val Float.dp2px: Int get() = run {
    val scale: Float = Resources.getSystem().displayMetrics.density
    return (this * scale + 0.5f).toInt()
}

class MotionLayoutActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_motion_layout)
        val aaa = 48.dp
        val bbb = Dp(48F).value
        val ccc = dp2px(48F)
        val ddd = 48.dp2px
        Log.i("anim", "aaa:$aaa, bbb:$bbb, ccc:$ccc, ddd:$ddd")
    }

    fun dp2px(dpValue: Float): Int {
        return (0.5f + dpValue * Resources.getSystem().displayMetrics.density).toInt()
    }
}